<template>
  <div class="room_left">
    <invite-vue v-if="invite"></invite-vue>
    <div class="info">
      <div class="house_owner">
        <img :src="$store.state.userinfo.picture" alt="">
        <span>{{$store.state.userinfo.name}}</span>
      </div>
      <div class="room_info">
        <p>
          <svg class='icon' aria-hidden='true'>
            <use xlink:href='#icon-liaotianshi-dating'></use>
          </svg>
          房间号：<span>{{RoomInfo.chatid}}</span></p>
        <p>
          <svg class='icon' aria-hidden='true'>
            <use xlink:href='#icon-pindao'></use>
          </svg>
          频道：<span>{{RoomInfo.channel}}</span></p>
        <p>
          <span v-if="$store.state.userinfo.username==RoomInfo.username" @click="removeRoom" class="exit">
            <svg class='icon' aria-hidden='true'>
              <use xlink:href='#icon-jiesan'></use>
            </svg>
            解散房间</span>
          <span class="invite" @click="invite = true">
            <svg class='icon' aria-hidden='true'>
              <use xlink:href='#icon-yaoqingjiaru'></use>
            </svg>
            邀请好友</span>
        </p>
      </div>
    </div>
    <div class="user_list_box">
      <ul class="user_list">
        <div class="title">
          <h5>用户列表</h5>
          <span>
            <svg class='icon' aria-hidden='true'>
              <use xlink:href='#icon-renshu'></use>
            </svg>
            <span>{{userList.length}}</span>
          </span>
        </div>
        <li class="user_box" v-for="(item,index) in userList" :key="index">
          <div class="user">
            <img :src="item.picture" :alt="item.name">
            <span>{{item.name}}</span>
          </div>
          <div class="room_root" v-if="item.username==RoomInfo.username">
            <span>
              <svg class='icon' aria-hidden='true'>
                <use xlink:href='#icon-index1'></use>
              </svg>
              房主</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import inviteVue from "./invite.vue"
export default {
  name: 'Userlist',

  data() {
    return {
      userList: [], // 当前房间用户列表
      invite: false, // 是否邀请好友
    };
  },

  props:{
    RoomInfo:Object, // 房间信息
    UserList:Object // 房间用户列表
  },

  watch: {
    // 监听用户列表
    UserList(newVal){
      this.userList = newVal.data
    },
  },

  mounted() {
    this.init()
  },

  methods: {
    // 初始化
    init(){
      this.userList = this.RoomInfo.userList
    },
    // 解散房间
    removeRoom(){
      if(confirm('是否要解散房间?')){
        this.$emit('removeRoom')
      }
    }
  },
  components: {
    inviteVue
  }
};
</script>

<style scoped>
.icon{
  font-size: 1rem;
  vertical-align: text-bottom;
}
.room_left{
  background-color: white;
  border-top: 1px solid gray;
}
.room_left .info{
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border-bottom: 1px solid gray;
  padding: 5px 0 5px 5px;
  background-image: url('../../../assets/image/userBG.jpg');
  background-size: cover;
}
.info .house_owner{
  display: flex;
  max-width: 100px;
  flex-direction: column;
  align-items: center;
  font-size: 0.8rem;
  color: gray;
  text-align: center;
}
.house_owner img{
  width: 55px;
  height: 55px;
  border-radius: 50%;
}
.info .room_info{
  flex: 1;
  font-size: 0.6rem;
  display: flex;
  flex-direction: column;
}
.room_info p{
  margin: 5px;
}
.room_info span{
  color: gray;
}
.user_list_box{
  width: 100%;
  overflow: hidden;
}
.user_list{
  width: 110%;
  overflow-y: scroll;
  max-height: 400px;
}
.user_list .user_box{
  border-bottom: 1px solid rgb(192, 192, 192);
  padding: 10px;
  padding-right: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-image: url('../../../assets/image/userBG.jpg');
  background-size: cover;
}
.user_list .title{
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px;
  font-size: 0.8rem;
  color: gray;
}
.user_list .title .icon{
  font-size: 1.2rem;
}
.user_list .title span{
  display: flex;
  align-items: center;
}
.user_list .user_box .user{
  display: flex;
  align-items: center;
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: gray;
}
.user_list li img{
  width: 33px;
  height: 33px;
  margin-right: 6px;
}
.room_root{
  font-size: 0.6rem;
  padding: 4px;
  border: 1px solid gray;
  background-color: green;
  color: white;
}
.room_info .exit,.room_info .invite{
  display: inline-block;
  color: red;
  cursor: pointer;
  transition: all .3s ease;
  margin: 4px;
}
.room_info .invite{
  color: gray;
}
.room_info .invite:hover{
  color: green;
}
@media screen and (max-width: 800px){
  .room_box .user_list .user_box{
    display: none;
  }
}
</style>